<?php

class Commdata_Industry_Module extends CI_Module {

	private $_data = array();

	public function __construct() {
		parent::__construct();
		$this->load->model('Category_model', 'c');
		$this->_data['firstoption'] = '<option value="">请选择</option>';
	}

	public function getIndustryName($industryid = '', $industrysubid = '')
	{
		$this->_data['industrylist'] = $this->getIndustry($industryid,'return');
		$this->_data['industrysublist'] = $this->getIndustrysub($industryid, $industrysubid, 'return');

		$this->_data['industryid']	= $industryid;
		$this->_data['industrysubid'] = $industrysubid;
		$this->load->view("industry", $this->_data);
	}


	// 获取大类行业名数据
	public function getIndustry($industryid = '', $rettype='html')
	{
		$retdata = array();
		$data = $this->c->getIndustry($industryid);

		$retdata = $this->_data['firstoption'] . array2option($data, $industryid);

		if ($rettype == 'html')
		{
			exit($retdata);
		}
		else if ($rettype == 'json')
		{
			$ret['code'] = '1';
			$ret['msg'] = $retdata;
			exit(json_encode($ret));
		}
		else if ($rettype == 'return')
		{
			return $retdata;
		}
	}

	// 获取小类航行名数据
	public function getIndustrysub($industryid, $industrysubid = '', $rettype = 'html')
	{
		if (empty($industryid)) return $this->_data['firstoption'];

		$retdata = array();
		$data = $this->c->getIndustrysub($industryid);
		$retdata = $this->_data['firstoption'] . array2option($data, $industrysubid);
		if ($rettype == 'html')
		{
			exit($retdata);
		}
		else if ($rettype == 'json')
		{
			$ret['code'] = '1';
			$ret['msg'] = $retdata;
			exit(json_encode($ret));
		}
		else if ($rettype == 'return')
		{
			return $retdata;
		}
	}
	

}
